package com.lee.demo1.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.com.mylib.www.MD5Utils;

import com.lee.demo1.business.SysUserBusiness;
import com.lee.demo1.domain.SysMenu;
import com.lee.demo1.domain.SysRole;
import com.lee.demo1.domain.SysRoleMenuKey;
import com.lee.demo1.domain.SysUser;

@Controller
@RequestMapping("sysrole")
public class SysRoleController {
	
	private static Logger logger = LoggerFactory.getLogger(SysRoleController.class);
	
	@Resource
	private SysUserBusiness sysUserBusiness;
	
	
	/**
	 * 进入角色（用户组）列表页面
	 * @return
	 */
	@RequestMapping(params = "method=list")
	public String list(Model model,Integer sysRoleId){
		
		List<SysRole> roles = sysUserBusiness.getRoles();
		model.addAttribute("roles", roles);
		
		List<SysMenu> menus = sysUserBusiness.getMenus();
		model.addAttribute("menus", menus);
		
		if(null != sysRoleId && sysRoleId > 0) {
			model.addAttribute("sysRoleId", sysRoleId);
			List<SysRoleMenuKey> roleMenus = sysUserBusiness.getRoleMenus(sysRoleId);
			model.addAttribute("roleMenus", roleMenus);
		}
		
		return "admin/sysrole/list";
	}
	
	@RequestMapping(params = "method=updatePermission")
	public String updatePermission(Integer sysRoleId, String checkedMenuIds){
		sysUserBusiness.updateRoleMenu(sysRoleId,checkedMenuIds);
		return "redirect:/sysrole?method=list&sysRoleId=" + sysRoleId; 
	}
	
	
	
	
	
}
